package com.bqtv.sport.ui.home.fragment

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewbinding.ViewBinding
import androidx.viewpager.widget.ViewPager
import com.bqtv.sport.R
import com.bqtv.sport.adapter.LiveAnalyzeDataAdapter
import com.bqtv.sport.adapter.LiveAnalyzeHtftAdapter
import com.bqtv.sport.adapter.LiveAnalyzeMatchesAdapter
import com.bqtv.sport.adapter.LiveAnalyzePointAdapter
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.app.AppFragment
import com.bqtv.sport.databinding.FragmentLiveAnalyzeBinding
import net.lucode.hackware.magicindicator.ViewPagerHelper
import java.util.ArrayList


class LiveAnalyzeFragment :
    AppFragment<FragmentLiveAnalyzeBinding, AppActivity<ViewBinding>>() {
    private var mViewList: MutableList<Fragment> = ArrayList ()

    companion object {
        private const val INTENT_KEY_TYPE = "type"
        fun newInstance(): LiveAnalyzeFragment {
            val fragment = LiveAnalyzeFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }

        fun newInstance(type: String?): LiveAnalyzeFragment {
            val fragment = LiveAnalyzeFragment()
            val bundle = Bundle()
            bundle.putString(INTENT_KEY_TYPE, type)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getViewBinding() = FragmentLiveAnalyzeBinding.inflate(layoutInflater)

    override fun initView() {
        mViewList.add(LiveAnalyzeDetailFragment.newInstance())
        mViewList.add(LiveAnalyzeCompareFragment.newInstance())
        binding.vpLive.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(i: Int, v: Float, i1: Int) {
            }

            override fun onPageSelected(position: Int) {

            }

            override fun onPageScrollStateChanged(i: Int) {
            }
        })
        binding.vpLive.setOffscreenPageLimit(4)
        binding.vpLive.setAdapter(object : FragmentPagerAdapter(getChildFragmentManager()) {
            override fun getItem(i: Int): Fragment {
                return mViewList.get(i)
            }

            override fun getCount(): Int {
                return mViewList.size
            }
        })

    }

    override fun initData() {

        initListener()
    }

    private fun initListener() {
        setOnClickListener(binding.tvDetail,binding.tvCompare)
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view) {
            binding.tvDetail -> {
                binding.tvDetail.setTextColor(Color.parseColor("#FFFFFF"))
                binding.tvDetail.setBackgroundResource(R.drawable.button_theme)
                binding.tvCompare.setTextColor(Color.parseColor("#222222"))
                binding.tvCompare.setBackgroundResource(R.drawable.bg_round_ffffff)
                binding.vpLive.setCurrentItem(0)
            }
            binding.tvCompare -> {
                binding.tvCompare.setTextColor(Color.parseColor("#FFFFFF"))
                binding.tvCompare.setBackgroundResource(R.drawable.button_theme)
                binding.tvDetail.setTextColor(Color.parseColor("#222222"))
                binding.tvDetail.setBackgroundResource(R.drawable.bg_round_ffffff)
                binding.vpLive.setCurrentItem(1)
            }
        }
    }
}

